package org.babygo.connect.handler.server.msg;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

import java.net.InetSocketAddress;

import org.babygo.connect.NettyFileOperator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ReciveNewConnectGroupHandler extends ChannelInboundHandlerAdapter{
	private Logger log = LoggerFactory.getLogger(ReciveNewConnectGroupHandler.class);

	@Override
	public void channelActive(ChannelHandlerContext ctx) throws Exception {
		InetSocketAddress address = (InetSocketAddress) ctx.channel().remoteAddress();
		NettyFileOperator.OPERTATOR.writeLog("[服务端]收到来自"+ address.toString() + "的连接\n");
		if(!NettyFileOperator.OPERTATOR.receiveNewConnect(address.toString())){
			log.info("允许连接");
		} else{
			log.info("拒绝连接");
			ctx.channel().close();
		}
	}
}
